// packageA/pages/choujiang5/choujiang5.js
const app = getApp()
const INTERVAL = 10000;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    ggid: '',
    gglist: '',
    autoplay: true,
    interval: 2000,
    duration: 500,
    name:'',
    xinxi: '',
    tanchuang13:false,
    tanchuang13_flag:false
  },
  z_sea(e) {
    this.setData({
      name: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    this.timer = setInterval(function () {
      that.z_kaihei3()
      // 这里可以执行定时器需要执行的任务
    }, INTERVAL);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.z_jilu3()
    this.z_jilu()
    this.z_kaihei3()
  },
  z_kaihei3() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/member_tj/tjcgTanInfo',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.data != '') {
          _this.setData({
            xinxi: res.data.data,
            tanchuang13: true
          })
        }
      }
    })
  },
  z_kaihei5() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "tjhd_id":_this.data.xinxi.id
    }
    wx.request({
      url: app.apiurl + 'api/member_tj/upTjcgTanInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
          _this.setData({
            tanchuang13: false,
          })
      }
    })
  },
  z_kaihei4() {
    let _this = this
    _this.setData({
      tanchuang13: false
    })
    _this.z_kaihei5()
  },
  guanggao1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.guanggao2()
      }
    })
  },
  guanggao2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=18',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          gglist: res.data.data[0]
        })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  z_jilu3(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/config/unprizeList?fbwz_type=3',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          mylist:res.data.data
        })
      }
    })
   },
   z_jilu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/member_tj/getTjActivityListNew?name='+_this.data.name+'&page_no=1&page_num=100',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          list:res.data.data
        })
      }
    })
   },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})